require("../util.js");
require("../component/components.js");
// require("../component/purchaseHeader.js");
// require("../component/footer.js");
require("../../jsMt/util.js");
var vm = new Vue({
    el:"#goodsClassify",
    data:{
        number:0,//下标
        id:"",//分类id
        name:"",//分类名称
        categoryList:{},//分类列表
        subCategoryList:{}//子分类列表
    },
    mounted:function(){
        this.getCategoryList();
    },
    methods:{
        //后退
        getBack:function(){
            history.go(-1);
        },
        bgimg:function(url){
            url = url?url:"";
            return {
                "background-image":'url("'+url+'"),url("")'
            }
        },
        //乐购一级分类
        getCategoryList:function(){
            var that=this;
            this.ajax({url:"/purchase/getCategoryList",dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.categoryList=b.json.data;
                    console.log(that.categoryList[0]);
                    that.getSubCategoryList(that.categoryList[0]);
                }else{
                    vm.$refs.prompt.toast("获取分类失败！")
                }
            });
        },
        //乐购子分类
        getSubCategoryList:function(item){
            var that=this;
            that.subCategoryList={};
            that.id=item.categoryId;
            that.name=item.name;
            this.ajax({url:"/purchase/getSubCategoryList",data:{id:that.id},dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.subCategoryList=b.json.data;
                }else{
                    vm.$refs.prompt.toast("获取子分类失败！")
                }
            });
        },
        //跳转页面
        getNext:function(item){
            location.href="/purchase/goodsList?categoryId="+item.categoryId+"&name="+encodeURI(item.name);
        }
    }
});